package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.util.KiteMapUtils;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttrValue;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteOfferInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/*
计费类型枚举初始化
 */
public class BigDataFeeTypeAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {
    @Autowired
    private IQuerySceneInstService querySceneInstService;

    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        Map<String,Object> oppoDetail=  querySceneInstService.getExtParameterValue(data.getSceneInstId(),"OPPO_DETAIL");
        Map<String,Map> oppoAttr = KiteMapUtils.getMap(oppoDetail,"PROD_ATTRS");
        boolean flag = false;
/*        if(KiteMapUtils.isNotEmpty(oppoAttr)&&false){
            Map<String,Map> oppoMebs = KiteMapUtils.getMap(oppoDetail,"OPPO_MEMBERS");
            if(KiteMapUtils.isNotEmpty(oppoMebs)){
                Set<String> keys = oppoMebs.keySet();
                if(keys.contains("200000000001320")&&keys.contains("200000000001318")&&!keys.contains("200000000001321")&&!keys.contains("200000000001319")){
                    flag = true;
                }
            }
        }else {

        }*/
        List<KiteOfferInst> kiteOfferInsts = querySceneInstService.listMainOfferInsts(data.getSceneInstId());
        List<String> keys =  kiteOfferInsts.stream().map(it->it.getOfferId()).collect(Collectors.toList());
        if(keys.contains("200000000001320")&&keys.contains("200000000001318")&&!keys.contains("200000000001321")&&!keys.contains("200000000001319")){
            flag = true;
        }
        List<KiteAttrValue> kiteAttrValues = attr.getAttrValues();
        if(!flag){
            kiteAttrValues = kiteAttrValues.stream().filter(it->!KiteStringUtils.equals(it.getAttrValue(),"100000563")).collect(Collectors.toList());
        }
        attr.setAttrValues(kiteAttrValues);
        super.after(attr, inst, data);
    }
}
